package com.kitty.game.player.serializer;

import com.kitty.game.role.model.Role;
import com.kitty.game.market.model.MarketTransactionBox;
import com.kitty.game.utils.JsonUtils;
import org.apache.commons.lang3.StringUtils;

public class MarketTransactionSerializer implements IPlayerPropSerializer {
    @Override
    public void serialize(Role player) {
        if (player.getTransactionBox() != null) {
            player.setTransactionBoxJson(JsonUtils.object2String(player.getTransactionBox()));
        }
    }

    @Override
    public void deserialize(Role player) {
        String json = player.getTransactionBoxJson();
        if (StringUtils.isNotBlank(json)) {
            player.setTransactionBox(JsonUtils.string2Object(json, MarketTransactionBox.class));
        } else {
            player.setTransactionBox(new MarketTransactionBox());
        }
    }
}
